package com.yss.netty.protocol;

import com.yss.exception.SerializeException;
import com.yss.netty.util.serialize.ISerialize;
import com.yss.netty.util.serialize.JsonSerializeUtil;
import com.yss.netty.util.serialize.ProtubufSerializeUtil;
import com.yss.netty.util.serialize.StringSerializeUtil;

@SuppressWarnings("all")
public enum SerType {
    /**
     * String
     */
    STRING,
    /**
     * JSON
     */
    JSON,
    /**
     * ProtoBuf
     */
    PROTOBUF;

    public static ISerialize matchUtilBySerType(final SerType serType) {
        ISerialize iSerialize;
        switch (serType) {
            case STRING: {
                iSerialize = new StringSerializeUtil();
                break;
            }
            case JSON: {
                iSerialize = new JsonSerializeUtil();
                break;
            }
            case PROTOBUF: {
                iSerialize = new ProtubufSerializeUtil();
                break;
            }
            default: {
                throw new SerializeException(String.format("Server does not support %s of serialization", serType.name()));
            }
        }
        return iSerialize;
    }
}
